package com.gxa.controller.asset;

import com.github.pagehelper.PageInfo;
import com.gxa.common.utils.R;
import com.gxa.entity.asset.AuthApply;
import com.gxa.entity.asset.ConnectApply;
import com.gxa.entity.asset.search.ConnectApplySearchMap;
import com.gxa.service.asset.ConnectApplyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import static com.gxa.common.utils.R.error;
import static com.gxa.common.utils.R.ok;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yjl
 * @since 2022-10-12 11:37:51
 */
@Api(tags = "设备移交--->移交申请")
@RestController
@RequestMapping("/connect-apply")
public class ConnectApplyController {

    @Autowired
    private ConnectApplyService service;


    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("资产移交申请列表接口")
    @GetMapping("/list")
    public R queryAll(ConnectApplySearchMap map){
        PageInfo<ConnectApply> info = service.queryByPage(map);
        return ok("successs").put("data",info).put("department",service.getDepts());
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("新增资产移交申请接口")
    @PostMapping("/add")
    public R add(@RequestBody ConnectApply device){
        boolean save = service.save(device);
        if (save){
            return R.ok("添加成功！");
        }
        return error("add fail");
    }

    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("删除资产移交申请接口")
    @DeleteMapping("/del/{id}")
    public R del(@PathVariable("id") Integer id){
        boolean b = service.removeById(id);
        if(b){
            return R.ok("删除成功！");
        }

        return error("del error");
    }
    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("根据id查询资产移交申请接口")
    @GetMapping("/queryById/{id}")
    public R queryById(@PathVariable("id") Integer id){
        ConnectApply connectApply = service.getById(id);
        if(connectApply != null){
            return R.ok("查询成功！").put("data",connectApply);
        }
        return error("query error");
    }
    @CrossOrigin(origins = "*", maxAge = 3600)//跨越请求配置
    @ApiOperation("编辑资产授权申请接口")
    @PutMapping("/edit")
    public R edit(@RequestBody ConnectApply device){
        boolean b = service.updateById(device);
        if(b){
            return R.ok("更新成功!");
        }

        return error("edit error");
    }
}
